﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLTV.Forms.KhaiBao
{
    public partial class frmContractList : BaseForm
    {
        public frmContractList()
        {
            InitializeComponent();

        }
        public frmContractList(string _crewID)
        {
            InitializeComponent();
            crewID = _crewID;
        }

        public string crewID { get; set; }

        private void frmContractList_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsContract.tblcontractList' table. You can move, or remove it, as needed.


            if (crewID == null)
                this.tadContractlist.Fill(this.dsContract.tblcontractList);
            else
                this.tadContractlist.FillByCrewID(this.dsContract.tblcontractList, crewID);

            this.tblVesselTableAdapter.Fill(this.dsVessel.tblVessel);
            this.tblCrewTableAdapter.Fill(this.dsCrew.tblCrew);
            this.tblEmployerTableAdapter.Fill(this.dsContract.tblEmployer);

        }

     

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (XtraMessageBox.Show(rm.GetString("sConfirm", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
            {
                int maContract = Convert.ToInt32(((DataRowView)tblContractBindingSource.Current).Row["nContractId"]);
                tblContractBindingSource.RemoveCurrent();
                tblContractBindingSource.EndEdit();
                tblContractTableAdapter1.Delete(maContract);
                

            }
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmContract f = new frmContract((int)viewContract.GetFocusedRowCellValue(colnContractId));
            f.isNew = false;
            f.ShowDialog();
            tblContractBindingSource.DataSource = this.tadContractlist.GetData();
        }

        private void barIn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmContract f = new frmContract((int)viewContract.GetFocusedRowCellValue(colnContractId));
            f.isNew = false;
            f.check = false;
            f.WindowState = FormWindowState.Minimized;
            f.ShowInTaskbar = false;
            f.Show();
            f.XemHD();
            f.Close();
        }

        private void radStatus_EditValueChanged(object sender, EventArgs e)
        {

            switch (((RadioGroup)(sender)).EditValue.ToString())
            {
                case "allin":
                    tblContractBindingSource.Filter = "cStatus='On Board' or cStatus='On Vacation' or cStatus='New Crew'";
                    break;
                case "onboard":
                    tblContractBindingSource.Filter = "";
                    tblContractBindingSource.Filter = "cStatus='On Board'";
                    break;
                case "onretire":
                    tblContractBindingSource.Filter = "";
                    tblContractBindingSource.Filter = "cStatus='On Retire'";
                    break;
                case "onvacation":
                    tblContractBindingSource.Filter = "";
                    tblContractBindingSource.Filter = "cStatus='On Vacation'";
                    break;
                case "onresign":
                    tblContractBindingSource.Filter = "";
                    tblContractBindingSource.Filter = "cStatus='On Resign'";
                    break;
                case "newcrew":
                    tblContractBindingSource.Filter = "";
                    tblContractBindingSource.Filter = "cStatus='New Crew'";
                    break;
                case "leftall":
                    tblContractBindingSource.Filter = "";
                    tblContractBindingSource.Filter = "cStatus='On Resign' or cStatus='On Retire'";
                    break;
            }
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmContract f = new frmContract();
            f.isNew = true;
            f.ShowDialog();
            tblContractBindingSource.DataSource = this.tadContractlist.GetData();
        }

        private void viewContract_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {

            if (e.Column == left && e.RowHandle>-1)
            {
                if (viewContract.GetRowCellValue(e.RowHandle, status).ToString() != "On Board")
                {
                    e.DisplayText = "";
                }
            }
        }
    }
}